package com.ahwei.common.rest.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：ahWei
 * Email: ahwei163@qq.com
 * Date: 2022-05-20 15:32:20
 * Description: 这是一个Java文件！
 */
@Configuration
/*@OpenAPIDefinition(info = @Info(title = "Employee API", version = "1.0", description = "Documentation Employee API v1.0"),
        externalDocs = @ExternalDocumentation(description = "参考文档", url = "https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X-Annotations"))*/
public class SwaggerAutoConfiguration {
    /**
     * API文档
     *
     * @return ·
     */
    @Bean
    public OpenAPI springShopOpenApi() {
        // 名字和创建的SecuritySchemes一致
        SecurityRequirement sr= new SecurityRequirement().addList("bearerAuth");
        List<SecurityRequirement> list = new ArrayList<>();
        list.add(sr);

        return new OpenAPI()
                .info(new io.swagger.v3.oas.models.info.Info().title("Shop API")
                        .description("网上商城")
                        .version("v0.0.1")
                        .license(new License().name("Apache 2.0").url("http://climbcloud.com")))
                .externalDocs(new io.swagger.v3.oas.models.ExternalDocumentation()
                        .description("SpringShop Wiki Documentation")
                        .url("https://climbcloud.com/docs"))
                // 这是基于HTTP协议的bearer认证实现
                .components(new Components().addSecuritySchemes("bearerAuth",
                        new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")))
                // 应用安全需要
                .security(list);
    }
}
